package com.li.manage.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import com.li.manage.dao.UserMapper;
import com.li.manage.model.User;
import com.li.manage.query.UserQuery;
import com.li.manage.service.UserService;


@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;
	@Autowired
	private PasswordEncoder passwordEncoder;
	
	public String login(String loginName, String loginPassword) {
		System.out.println("--------------我是改变的");
		User user = userMapper.getUserByLoginName(loginName);
		System.out.println(passwordEncoder.encode("123456"));
		if(user==null){
			return "noUser";
		}else if(!passwordEncoder.matches(loginPassword,user.getPassword())){
			return "passwordError";
		}else if(user.getState().intValue()==1){
			return "userTingYong";
		}else{
			return "success";
		}
	}

	@Override
	public User getUserByLoginName(String loginName) {
		return userMapper.getUserByLoginName(loginName);
	}

	@Override
	public List<User> getUserList(UserQuery userQuery) {
		return userMapper.getUserList(userQuery);
	}

	@Override
	public User getUserByCode(String code) {
		return userMapper.getUserByCode(code);
	}

	@Override
	public String getMaxCode() {
		return userMapper.getMaxCode();
	}

	@Override
	public void addUser(User user) {
		userMapper.insertSelective(user);
	}

	@Override
	public void updateByCode(User user) {
		userMapper.updateByCode(user);
	}

	@Override
	public void deleteUserByCode(String code) {
		userMapper.deleteUserByCode(code);
	}
	
	
	
}
